﻿using System;
using ClieOp;
using NUnit.Framework;

namespace ClieOpTest
{
    [TestFixture]
    public class UtilityTest
    {
        [Test]
        public void ClieOpAsciiTest()
        {
            const string expected = "abcDEF012()*aaaaaaceeeeiiii";
            string actual = Utility.ClieOpAscii("abcDEF012()[]*àáâãäåçèéêëìíîï");
            Assert.AreEqual(expected, actual);
        }

        [Test]
        public void ClieOpDateToDateTimeTest()
        {
            Assert.AreEqual(new DateTime(2000, 2, 1), Utility.ClieOpDatumToDateTime(010200));
            Assert.AreEqual(new DateTime(2099, 12, 31), Utility.ClieOpDatumToDateTime(311299));
        }

        [Test]
        public void ClieOpDatumTest()
        {
            long expected = 131299;
            long actual = Utility.ClieOpDatum(new DateTime(1999, 12, 13));
            Assert.AreEqual(expected, actual);
            expected = 10199;
            actual = Utility.ClieOpDatum(new DateTime(2099, 1, 1));
            Assert.AreEqual(expected, actual);
        }

        [Test]
        public void ClieOpNumTest()
        {
            string expected = "0000000123";
            string actual = Utility.ClieOpNum("123", 10);
            Assert.AreEqual(expected, actual);
            expected = "2345678901";
            actual = Utility.ClieOpNum("12345678901", 10);
            Assert.AreEqual(expected, actual);
        }

        [Test]
        public void ClieOpStringTest()
        {
            string expected = "abcDEF012()*aaaaaace";
            string actual = Utility.ClieOpString("abcDEF012()[]*àáâãäåçèéêë", 20);
            Assert.AreEqual(expected, actual);
            expected = "a         ";
            actual = Utility.ClieOpString("a", 10);
            Assert.AreEqual(expected, actual);
        }

        [Test]
        public void IsValidBankaccountTest()
        {
            BankAccountCheckStatus giro = Utility.IsValidBankaccount(5542965);
            Assert.AreEqual(BankAccountCheckStatus.NotABankAccount, giro);
            BankAccountCheckStatus bank = Utility.IsValidBankaccount(786892692);
            Assert.AreEqual(BankAccountCheckStatus.Valid, bank);
            BankAccountCheckStatus invalid = Utility.IsValidBankaccount(786892693);
            Assert.AreEqual(BankAccountCheckStatus.InValid, invalid);
        }
    }
}